package com.yxq.mdt.app.modules.shoppingcart.prestener;


import com.yxq.mdt.app.base.BasePresenter;
import com.yxq.mdt.app.modules.shoppingcart.bean.CartBean;
import com.yxq.mdt.app.modules.shoppingcart.model.CartModel;
import com.yxq.mdt.app.net.ApiModel;

import java.util.List;

public class CartPresenter extends BasePresenter<ICartContract.View, CartModel> implements ICartContract.Presenter {

    public CartPresenter(ICartContract.View view, CartModel model) {
        super(view, model);
    }

    @Override
    public void cartList() {

        mBaseModel.cartList(new ApiModel.CommonCallback<CartBean>() {
            @Override
            public void onSuccess(CartBean beanList) {
                mRootView.onLoadSuccess(beanList);
            }

            @Override
            public void onError(String errMsg) {
                mRootView.onLoadFailed(errMsg);
            }
        });
    }

    @Override
    public void cartDelete(List<Integer> position,String list) {
        mBaseModel.cartDelete(list, new ApiModel.CommonCallback<String>() {
            @Override
            public void onSuccess(String beanList) {
                mRootView.onDeleteSuccess(position,beanList);
            }

            @Override
            public void onError(String errMsg) {
                mRootView.onDeleteFailed(errMsg);
            }
        });
    }

    @Override
    public void cartEdit(String list) {
        mBaseModel.cartEdit(list, new ApiModel.CommonCallback<String>() {
            @Override
            public void onSuccess(String beanList) {
                mRootView.onEditSuccess(beanList);
            }

            @Override
            public void onError(String errMsg) {
                mRootView.onEditFailed(errMsg);
            }
        });
    }
}
